import Vue from 'vue'
import App from './App'
import router from './router'

import axios from 'axios'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})

axios({
  url:'https://www.baidu.com/',
  method: 'get'
}).then((res) => {
  console.log(res)
}).catch((err) => {
  console.log(err)
  console.log('获取错误')
})
//当同时发生两个请求时,和promise的all方法相似
axios.all([axios({
  url:'http://www.xinlang.com',
  params:{
  type: 'sell',
  page: 5
  }
}),
  axios({

  })]).then((res) => {
    console.log(res)
  }).catch((err) => {
    console.log(err)
  })

axios.defaults.baseURL = ''//默认url
axios.defaults.timeout = ''//默认超时时间,超过此时间没获取到数据则报错单位为毫秒

const instance1 = axios.create({
  baseURL:'',
  timeout:''
})
instance1({
  url1:'', 
}).then()

instance1({
  url:'',
  params:{

  }
})
   

//5、使用封装的axios
import {request} from "./network/request.js"

request({
  url:'/home/data'
}, 
res => {
  console.log(res)
}, 
err => {
  console.log(err)
})

request({
  baseConfig: {

  },
  success: function (res) {

  },
  failure: function(err){

  }
})

request({
  url:'/home/index',
}).then(res => {
  console.log(res)
}).catch(err => {
  console.log(err)
})